package com.example.orderflow.controller.view;


import com.example.orderflow.controller.base.ABaseController;
import com.example.orderflow.entity.vo.ResponseVO;
import com.example.orderflow.exception.BusinessException;
import com.example.orderflow.service.OrderEquipmentService;
import com.example.orderflow.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName OrderDetailsController
 * @Description: 查看订单详细信息
 * @Since JDK 1.8
 * @Create 2024/7/12 16:07
 */

@RestController
public class OrderDetailsController extends ABaseController {

    @Autowired
    OrderInfoService orderInfoService;
    @Autowired
    OrderEquipmentService orderEquipmentService;

    /**
     * @create: 2024/7/12 16:07
     * @description: 根据订单类型查询订单详细信息
     * @param: orderId 订单编号
     * @return List<orderEquipment>
     */
    @PostMapping("/OrderDetails")
    public ResponseVO orderDetails(@RequestBody Map<String,String> map) {

        try {
            String orderId = map.get("orderId");
            //判断orderId不为空 && orderId所表示的订单在orderinfo表中存在
            if (orderId.isEmpty() || orderInfoService.getOrderInfoByOrderId(orderId).equals(null)){
                throw new BusinessException("订单编号不存在");
            }
            return getSuccessResponseVO(orderEquipmentService.selectByOrderId(orderId));
        }catch (Exception e){
            throw new BusinessException("订单编号不存在或订单编号为null，如非上述异常，请联系管理员处理");
        }

    }
}
